﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using AKMII.DMRA.Common;

namespace AKMII.DMRA.Business.Rule
{
    public class CurrentPeriod
    {
        public static int Month
        {
            get
            {
                List<MonthSetting> settings = SystemConfiguration.MonthSettings;

                foreach (MonthSetting setting in settings)
                {
                    if (DateTime.Now.Date <= setting.EndDate.Date 
                        && DateTime.Now.Date >= setting.StartDate.Date)
                    {
                        return setting.MonthName;
                    }
                }

                return 0;
            }
        }

        public static int Year
        {
            get
            {
                return Convert.ToInt32(SystemConfiguration.CommonSetting.CurrentYear);
            }
        }

        public static bool IsOrderPeriod
        {
            get
            {
                List<MonthSetting> settings = SystemConfiguration.MonthSettings;
                foreach (MonthSetting setting in settings)
                {
                    if (DateTime.Now.Date <= setting.CutOffEndDate.Date
                        && DateTime.Now.Date >= setting.CutOffStartDate.Date)
                    {
                        return true;
                    }
                }

                return false;
            }
        }

        public static bool IsImportPeriod
        {
            get
            {
                foreach (MonthSetting setting in SystemConfiguration.MonthSettings)
                {
                    if (DateTime.Now.Date >= setting.StartDate.Date && DateTime.Now.Date < setting.CutOffStartDate)
                    {
                        return true;
                    }
                }

                return false;
            }
        }

        public static bool IsUploadPeriod
        {
            get
            {
                foreach (MonthSetting setting in SystemConfiguration.MonthSettings)
                {
                    if (DateTime.Now.Date.Date == setting.UploadDate.Date)
                    {
                        return true;
                    }
                }

                return false;
            }
        }

        public static bool IsSendSummaryMailPeriod
        {
            get
            {
                foreach (MonthSetting setting in SystemConfiguration.MonthSettings)
                {
                    if (DateTime.Now.Date == setting.CutOffEndDate.Date)
                    {
                        return true;
                    }
                }

                return false;
            }
        }

        public static bool IsSendSummaryReportPeriod
        {
            get
            {
                foreach (MonthSetting setting in SystemConfiguration.MonthSettings)
                {
                    if (DateTime.Now.Date == setting.CutOffEndDate.AddDays(1).Date)
                    {
                        return true;
                    }
                }

                return false;
            }
        }

        public static bool IsSendWeeklyReminderPeriod
        {
            get
            {
                foreach (MonthSetting setting in SystemConfiguration.MonthSettings)
                {
                    if (DateTime.Now.Date == setting.CutOffStartDate.Date.AddDays(-7))
                    {
                        return true;
                    }
                }

                return false;
            }
        }
    }
}
